package com.example.app.pages.main.home.justTestPage

import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.width
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.VerticalAlignmentLine
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import com.example.app.components.MyButton.MyButton
import com.example.app.components.MyText.MyText
import com.google.accompanist.permissions.ExperimentalPermissionsApi

@OptIn(ExperimentalLayoutApi::class,
    ExperimentalPermissionsApi::class,
    ExperimentalMaterial3Api::class)
@Composable
fun JustTestPage() {
    var show by remember {
        mutableStateOf(false)
    }

    MyButton(onClick = {
        show = !show
    }) {
        MyText(text = "测试")
    }
    var density = LocalDensity.current
    var windowWidth = LocalConfiguration.current.screenWidthDp
    var windowHeight = LocalConfiguration.current.screenHeightDp
    var pxBottomNavicationBarHeight = WindowInsets.navigationBars.getBottom(density)
    var bottomNavicationBarHeight = with(density) {
        pxBottomNavicationBarHeight.toDp()
    }
    var offsetY =
        animateDpAsState(targetValue = if (show) windowHeight.dp * .25f - bottomNavicationBarHeight else windowHeight.dp)

    if (offsetY.value < windowHeight.dp) {
        Box(modifier = Modifier
            .fillMaxSize()
            .background(Color.Black.copy(alpha = .2f))) {
            Column(modifier = Modifier
                .width(windowWidth.dp)
                .offset(y = offsetY.value)
                .height(windowHeight.dp * .75f)
                .background(Color.Red),
                verticalArrangement = Arrangement.Bottom) {

            }
        }
    }
}



